package org.aeon.server.handler.Inbound;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.aeon.annotation.Incomplete;
import org.aeon.message.request.BlacklistModifyRequestMessage;

/**
 * @author: MissingAeon
 * @date: 2024/1/31 9:25
 * @description: 黑名单添加请求处理程序
 */
@Slf4j
@ChannelHandler.Sharable
@Incomplete
public class BlacklistModifyRequestHandler extends SimpleChannelInboundHandler<BlacklistModifyRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, BlacklistModifyRequestMessage msg) throws Exception {
        // final UserRelationService relationService = UserRelationServiceFactory.getService();
        // final UserDto owner = msg.getOwner();
        // final UserDto guest = msg.getGuest();
        // final Long guestId = UserServiceFactory.getService().getUserId(guest.getUsername());
        // final UserRelation relation = relationService.queryRelation(owner.getId(), guestId);
        // // 是添加
        // if (msg.isAdd()) {
        //     // 无关系或好友关系
        //     if (relation == null || relation.getIsFriend()) {
        //         final boolean b = relationService.addAssociations(owner.getId(), guestId, false);
        //         ctx.writeAndFlush(new BlacklistModifyResponseMessage(b, guest.getUsername() + "添加黑名单" + (b ? "成功" : "失败")));
        //     } else {
        //         ctx.writeAndFlush(new BlacklistModifyResponseMessage(false, guest.getUsername() + "已在黑名单中"));
        //     }
        // }
        // // 否则删除
        // else {
        //     if (relation != null && !relation.getIsFriend()) {
        //         final boolean b = relationService.disassociate(owner.getId(), guestId);
        //         ctx.writeAndFlush(new BlacklistModifyResponseMessage(b, guest.getUsername() + "移出黑名单" + (b ? "成功" : "失败")));
        //     } else {
        //         ctx.writeAndFlush(new BlacklistModifyResponseMessage(false, guest.getUsername() + "不存在于黑名单"));
        //     }
        // }
    }
}
